package org.pada.domain.event;


import lombok.Getter;
import org.pada.domain.AggregationRoot;

import java.util.Date;
import java.util.UUID;

/**
 * @author pengshen
 * @date 2022.05.21 08:11
 */
@Getter
public abstract class AbstractDomainEvent {
    private final UUID eventId;
    private final Date occurTime;
    private final AggregationRoot aggregationRoot;

    public AbstractDomainEvent(AggregationRoot aggregationRoot) {
        this.eventId = UUID.randomUUID();
        this.occurTime = new Date();
        this.aggregationRoot = aggregationRoot;
    }

    @Override
    public int hashCode() {
        return eventId.toString().hashCode();
    }

    @Override
    public boolean equals(Object event) {
        if (event == null) {
            return false;
        }
        if (this == event) {
            return true;
        }
        return this.eventId.equals(((AbstractDomainEvent)event).eventId);
    }
}
